package com.pounds.control;

import com.pounds.pojo.Admin;
import com.pounds.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("peaceful/admin")
public class AdminControl {

    @Autowired
    private AdminService adminService;

    @GetMapping("select")
    public List<Admin> getAdminList() {
        return adminService.getAdminList();
    }

    @GetMapping("new")
    public String addAdmin(String name, String account, String password, String contact, String note) {
        return adminService.addAdmin(name, account, password, contact, note);
    }

    @GetMapping("delete")
    public String deleteAdmin(int id) {
        return adminService.deleteAdmin(id);
    }

    @GetMapping("update")
    public String updateAdmin(int id, String name, String account, String password, String contact, String note) {
        return adminService.updateAdmin(id, name, account, password, contact, note);
    }

    @GetMapping("login")
    public String login(String account, String password) {
        return adminService.login(account, password);
    }
}
